package com.ruoyi.web.controller.his;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.his.domain.ReVillage;
import com.ruoyi.his.service.IReVillageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 村Controller
 * 
 * @author Alan
 * @date 2024-03-16
 */
@RestController
@RequestMapping("/his/village")
public class ReVillageController extends BaseController
{
    @Autowired
    private IReVillageService reVillageService;

    /**
     * 查询村列表
     */
//    @PreAuthorize("@ss.hasPermi('his:village:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReVillage reVillage)
    {
        startPage();
        List<ReVillage> list = reVillageService.selectReVillageList(reVillage);
        return getDataTable(list);
    }

    /**
     * 导出村列表
     */
//    @PreAuthorize("@ss.hasPermi('his:village:export')")
    @Log(title = "村", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ReVillage reVillage)
    {
        List<ReVillage> list = reVillageService.selectReVillageList(reVillage);
        ExcelUtil<ReVillage> util = new ExcelUtil<ReVillage>(ReVillage.class);
        return util.exportExcel(list, "村数据");
    }

    /**
     * 获取村详细信息
     */
//    @PreAuthorize("@ss.hasPermi('his:village:query')")
    @GetMapping(value = "/{code}")
    public AjaxResult getInfo(@PathVariable("code") String code)
    {
        return AjaxResult.success(reVillageService.selectReVillageByCode(code));
    }

    /**
     * 新增村
     */
//    @PreAuthorize("@ss.hasPermi('his:village:add')")
    @Log(title = "村", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReVillage reVillage)
    {
        return toAjax(reVillageService.insertReVillage(reVillage));
    }

    /**
     * 修改村
     */
//    @PreAuthorize("@ss.hasPermi('his:village:edit')")
    @Log(title = "村", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReVillage reVillage)
    {
        return toAjax(reVillageService.updateReVillage(reVillage));
    }

    /**
     * 删除村
     */
//    @PreAuthorize("@ss.hasPermi('his:village:remove')")
    @Log(title = "村", businessType = BusinessType.DELETE)
	@DeleteMapping("/{codes}")
    public AjaxResult remove(@PathVariable String[] codes)
    {
        return toAjax(reVillageService.deleteReVillageByCodes(codes));
    }
}
